package com.basic.common;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

import org.apache.log4j.Logger;

public class CommonCfg {
	private static Logger logger = Logger.getLogger(CommonCfg.class.getName());
	private Properties prop = new Properties();
	private static CommonCfg cc = null;

	private static CommonCfg init() {
		if (CommonCfg.cc == null)
			CommonCfg.cc = new CommonCfg();
		return CommonCfg.cc;
	}
	public static String readValue(String var) {
		return CommonCfg.init().getValue(var);
	}
	public static void refresh() {
		CommonCfg.cc = null;
	}

	
	private CommonCfg() {
		File f = new File(FuncStatic.getRootFilePath()+"common.properties"); 
		InputStream is = null;
		try {
			is = new FileInputStream(f);
			prop.load(is);
		} catch (Exception ex) {
			logger.error("common.properties 配置文件获取失败");
		} finally {
			try {
				if(is != null)
					is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		
	}

	private String getValue(String var) {
		return prop.getProperty(var);
	}
 
	public static boolean readBooleanValue(String var){
		String val = CommonCfg.init().getValue(var);
		if(val==null){
			return false;
		}
		if(val.equals("TRUE")){
			return true;
		}
		return false;
	}
	 
}
 
